<?php

function get_my_focused($usr_guid, $orderby = '') {
	
	$data = get_data("select ticker,name from dsq_user_focus where guid={$usr_guid} order by time $orderby");
	//print_r($data);
	$ret = array();
	foreach($data as $obj) {		
		$tmp["Ticker"] = $obj->ticker;
		$tmp["Name"] = $obj->name;
		
		$ret[] = $tmp;
	}
	return $ret;
}

function get_all_focused() {
	$data = get_data("select distinct ticker, name, max(time) dt from dsq_user_focus group by ticker order by dt");
	//print_r($data);
	$ret = array();
	foreach($data as $obj) {
		$tmp["Ticker"] = $obj->ticker;
		$tmp["Name"] = $obj->name;
		
		$ret[] = $tmp;
	}
	return $ret;
} 

function get_my_focused_ticker_only($usr_guid) {
	$data = get_data("select ticker from dsq_user_focus where guid={$usr_guid} order by time");
	$ret = array();
	foreach($data as $obj) {
		$ret[] = $obj->ticker;
	}
	return $ret;	
}

function get_all_focused_ticker_only() {
	$data = get_data("select distinct ticker, max(time) dt from dsq_user_focus group by ticker order by dt");
	//print_r($data);
	$ret = array();
	foreach($data as $obj) {
		$ret[] = $obj->ticker;
	}
	return $ret;
} 

function is_user_focused_ticker($user_guid, $ticker) {
	$data = get_data_row("select * from dsq_user_focus where guid='{$user_guid}' and ticker='{$ticker}'");
	//print_r($data);
	if ($data) {
		return true;
	}
	return false;
}

function get_users_by_focused_ticker($ticker) {
	$data = get_data("select guid from dsq_user_focus where ticker={$ticker} order by time desc");
	$ret = array();
	foreach($data as $obj) {
		$ret[] = $obj->guid;
	}
	return $ret;	
}